﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.Collections.Extensions;
using Abp.Domain.Repositories;
using Abp.Extensions;
using Abp.Linq.Extensions;
using crazy.Authorization;
using crazy.Goods.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace crazy.Goods
{
    [AbpAuthorize(PermissionNames.Pages_Goods)]
    public class GoodsAppService :
        AsyncCrudAppService<Goods, GoodsDto, Guid, PagedGoodsResultRequestDto,
                            CreateGoodsDto, GoodsDto>,
        IGoodsAppService
    {
        public GoodsAppService(IRepository<Goods, Guid> repository)//注入IRepository自动为Goods创建仓储
            : base(repository)
        {

        }

        /// <summary>
        /// 查询接口(使用Keyword查询商品名称)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        protected override IQueryable<Goods> CreateFilteredQuery(PagedGoodsResultRequestDto input)
        {
            return Repository.GetAll().WhereIf(!input.Keyword.IsNullOrWhiteSpace(), a => a.GoodsName.Contains(input.Keyword));
        }

    }
}
